package com.none.staff.managers;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

public class SharePreferenceManager {

    private  Context context;
    private SharedPreferences preferences;
    private static SharedPreferences.Editor editor;

    public SharePreferenceManager(Context context) {
        this.context = context;

    }

    @SuppressLint("CommitPrefEdits")
    public SharePreferenceManager getSharedPreferences(String sharedName) {
        preferences = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
        editor = preferences.edit();
        return this;
    }

    public SharePreferenceManager putString(String key, String value) {
        if (editor == null) {
            throw new NullPointerException("edit  can not null");
        }
        editor.putString(key, value);
        editor.apply();
        return this;
    }

    public SharePreferenceManager putBoolean(String key, Boolean value) {
        if (editor == null) {
            throw new NullPointerException("edit  can not null");
        }
        editor.putBoolean(key, value);
        editor.apply();
        return this;
    }

    public SharePreferenceManager putInt(String key, int value) {
        if (editor == null) {
            throw new NullPointerException("edit  can not null");
        }
        editor.putInt(key, value);
        editor.apply();
        return this;
    }


    public String getString(String key, String value) {
        if (preferences == null) {
            throw new NullPointerException("preferences can not null");
        }

        return preferences.getString(key, value);
    }


}
